package dk.kapetanovic.jaft.action;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import dk.kapetanovic.jaft.transaction.Transaction;

public class OpenFileOutputStreamAction extends OpenFileAction {

	private OutputStream out;
	private boolean append;
	
	public OpenFileOutputStreamAction(File original, 
		boolean append, Transaction transaction) {
		super(original, !append, transaction);
		this.append = append;
	}
	
	@Override
	public Object execute() throws IOException {
		out = new FileOutputStream(original, append);
		return out;
	}
	
	@Override
	public void close() throws IOException {
		if(out != null)
			out.close();
	}
}
